package sn.gandal.mobile.kalpet.data.server;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;


import sn.gandal.mobile.kalpet.data.entities.Account;

public class ServerRessourcesHelper extends IDataRemoteAcces {
	
	private static ServerRessourcesHelper instance= new ServerRessourcesHelper();
	
	public static  ServerRessourcesHelper getInstance() {
		 if (null==instance) {
	            instance = new ServerRessourcesHelper();
	        }
		 return instance;
	 }
	
	 
	 private ServerRessourcesHelper(){
		
	}
	@Override
	public String get(String addr, String path, Map params) throws ClientProtocolException, IOException {
		String url= addr+path;
		 HttpClient httpclient = new DefaultHttpClient();
    	 HttpGet request=new HttpGet(url);
    	 request.setHeader("content-type", "application/JSON");
    	    HttpResponse response = httpclient.execute(request);
    	    
    	    StatusLine statusLine = response.getStatusLine();
    	    String responseString =null;
    	    if(statusLine.getStatusCode()== HttpStatus.SC_OK){
    	        ByteArrayOutputStream out = new ByteArrayOutputStream();
    	        response.getEntity().writeTo(out);
    	        out.close();
    	        responseString = out.toString();
    	        //..more logic
    	    } else{
    	        //Closes the connection.
    	        response.getEntity().getContent().close();
    	        throw new IOException(statusLine.getReasonPhrase());
    	    }
    	
    	return responseString;
	}
	@Override
	public String put(String addr, String path, Map params) throws ClientProtocolException, IOException {
	
    	
    	return null;
	}
	@Override
	public String delete(String addr, String path, Map params) throws ClientProtocolException, IOException {
	
    	
    	return null;
	}


	@Override
	public String getUserData(String numero, String code) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public String getAccountById(String id) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public String authServer(String codeSecret, String numeroCli) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public String saveAccount(Account account) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public String saveCompteCredit() {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public String saveCompteCarte() {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public String getFriendsList(String numeroClient, String userPhoneToken,
			Date dateRefresh) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public String getAllHistorics(String numeroClient, String userPhoneToken,
			Date dateRefresh) {
		// TODO Auto-generated method stub
		return null;
	}
}
